package com.canace.novel.controller;

import com.canace.novel.core.common.resp.RestResp;
import com.canace.novel.core.constant.ApiRouterConsts;
import com.canace.novel.dto.req.UserLoginReqDto;
import com.canace.novel.dto.req.UserRegisterReqDto;
import com.canace.novel.dto.resp.UserLoginRegisterRespDto;
import com.canace.novel.serviece.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author canace
 * @version 1.0
 * @description 用户API模块
 * @date 2024/1/20 12:47
 */
@Tag(name = "UserController", description = "用户模块")
@RestController
@RequestMapping(ApiRouterConsts.API_FRONT_USER_URL_PREFIX)
@RequiredArgsConstructor

public class UserController {

    private final UserService userService;

    @Operation(summary = "用户注册")
    @PostMapping("register")
    public RestResp<UserLoginRegisterRespDto> userRegister(@Valid @RequestBody UserRegisterReqDto userRegisterReqDto){
        return userService.userRegister(userRegisterReqDto);
    }

    /**
     * 用户登录接口
     */
    @Operation(summary = "用户登录接口")
    @PostMapping("login")
    public RestResp<UserLoginRegisterRespDto> login(@Valid @RequestBody UserLoginReqDto dto) {
        return userService.userLogin(dto);
    }
}
